﻿#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

class Solution {
public:
    
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> pos;
        int ret = 0;
        int l = 0, n = s.length();
        for (int r = 0; r < n; r++) {
            char c = s[r];
            pos[c]++;
            while (pos[c] >= 2) {
                pos[s[l++]]--;
            }
            ret = max(ret, r - l + 1);
        }
        return ret;
    }
};

int main() {
    Solution solution;
    string input = "abcabcbb";
    int result = solution.lengthOfLongestSubstring(input);
    cout << "给定字符串中无重复字符的最长子串长度为: " << result << endl;
    return 0;
}